﻿@model Model.ETL_TaskInfo
@{
    ViewBag.Title = "编辑任务信息";
    Layout = "~/Views/Shared/_Main.cshtml";
}
@section Head{
    <style>
        .editTime
        {
            width: 240px;
            text-align: right;
            line-height: 22px;
            margin-top: 3px;
        }
        .TaskPlan
        {
            line-height: 25px;
        }
        .sel_TimeH, .sel_TimeM
        {
            width: 52px;
        }
        .bigType
        {
            display: none;
        }
    </style>
    <script type="text/javascript">
        var UrlArray = $.getUrlArray();
    </script>
    <script src="/Res/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <script src="/Res/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script src="/Scripts/TaskConfig.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            page_Init();
        });
        function page_Init() {
            var dbType = UrlArray["DBType"];
            if (dbType == "2") {
                $(".div_dataGridModel").hide();
                $(".bigType").show();
                var waits = '@Model.WaitTimes';
                if (waits == "") {
                    waits = "0:0:0";
                }
                var arr_wait = waits.split(":");
                $("#txt_WaitTimesH").val(arr_wait[0]);
                $("#txt_WaitTimesM").val(arr_wait[1]);
                $("#txt_WaitTimesS").val(arr_wait[2]);
            }
            bingDropdownList();

            $('.txt_TaskStartDate').datebox('setValue', '@Model.TaskStartDate');
            $('.txt_TaskEndDate').datebox('setValue', '@Model.TaskEndDate');
            if ('@Model.TaskID' != "") {
                // 联系人
                UserOpts.url = "/JobTask/GetTargetUserList?taskID=" + "@Model.TaskID"
                    + "&dbName=" + encodeURI(UrlArray["dbName"]);
                $("#dataGridUser").dg(UserOpts);

                if (dbType != "2") {
                    ModelOpts.url = "/JobTask/GetTaskDetailsList?taskID=" + "@Model.TaskID"
                    + "&type=T&dbName=" + encodeURI(UrlArray["dbName"]);
                    $("#dataGridModel").dg(ModelOpts);
                }
                GroupOpts.url = "/JobTask/GetTaskDetailsList?taskID=" + "@Model.TaskID"
                    + "&type=L&dbName=" + encodeURI(UrlArray["dbName"]);
                $("#dataGridGroup").dg(GroupOpts);
                switch ('@Model.TaskPlanType') {
                    case "1":
                        GetTaskPlanType("1");
                        break;
                    case "2":
                        var wdArr = '@Model.WeekDay'.split(",");
                        for (var j = 0; j < wdArr.length; j++) {
                            $(".WeekDay").each(function (i, d) {
                                if (d.value == wdArr[j])
                                    d.checked = true;
                            });
                        }
                        GetTaskPlanType("2");
                        break;
                    case "3":
                        GetTaskPlanType("3");
                        break;
                }

                var ftype = $("#txt_FrequencyType").val();
                $('.rad_FType').each(function () {
                    if ($(this).val() == ftype)
                        $(this).attr("checked", "checked");
                    else
                        $(this).removeAttr("checked");
                });
                var tst = $("#txt_TaskStartTime").val();
                if (ftype == 0) {
                    var h = tst.split(":");
                    $('.OnceH').val(h[0]);
                    $('.OnceM').val(parseInt(h[1]));
                }
                else {
                    var h = tst.split(":");
                    $('.IntervalFH').val(h[0]);
                    $('.IntervalFM').val(parseInt(h[1]));
                    var tet = $("#txt_TaskEndTime").val();
                    h = tet.split(":");
                    $('.IntervalTH').val(h[0]);
                    $('.IntervalTM').val(parseInt(h[1]));

                    var im = parseInt($("#txt_TaskEveryDayIntervalMinute").val());
                    var ihour = parseInt(im / 60);
                    var imin = im % 60;
                    $('.IntervalH').val(parseInt(ihour));
                    $('.IntervalM').val(imin);
                }
            }
        }
        function checkWaitTimes(v, tp) {
            v = checkNum(v);
            var rad_FType = $('input[name="rad_FType"]:checked').val();
            switch (tp) {
                case 1:
                    if (v > 0 && $("#txt_WaitTimesM").val() == "60")
                        $("#txt_WaitTimesM").val("59")
                    break;
                case 2:
                    var wh = $("#txt_WaitTimesH").val();
                    if (v >= 60) {
                        if (wh > 0)
                            v = 59;
                        else
                            v = 60;
                    }
                    if (v > 0 && $("#txt_WaitTimesS").val() == "60")
                        $("#txt_WaitTimesS").val("59")
                    break;
                case 3:
                    var wm = $("#txt_WaitTimesM").val();
                    if (v >= 60) {
                        if (wm > 0)
                            v = 59;
                        else
                            v = 60;
                    }
                    break;
            }
            return v;
        }
    </script>
}
<div style="margin: 5px;">
    <form id="ff" method="post">
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/filesave.png" />
            </td>
            <td width="300">
                编辑任务
            </td>
            <td align="right">
                <input id="btnSubmit" type="button" class="button" value="保存" onclick="return submitForm()" />
                <input id="btnBack" type="button" class="button" value="返回" onclick="btnBack_Click()" />
            </td>
        </tr>
    </table>
    <table class="table_bg" style="width: 100%;" cellpadding="0" cellspacing="0">
        <tr>
            <td style="text-align: right;" width="110">
                <span class="red">*</span>任务名称：
            </td>
            <td width="350">
                <input type="hidden" id="hdd_TaskID" name="TaskID" value="@Model.TaskID" />
                <input type="hidden" id="hdd_TaskStatus" name="TaskStatus" value="@Model.TaskStatus" />
                <input type="text" id="txt_TaskName" maxlength="50" name="TaskName" value="@Model.TaskName" style="width:300px" />
            </td>
            <td style="text-align: right;" width="110">
                <span class="red">*</span>任务类型：
            </td>
            <td>
                <select id="sel_TaskType" name="TaskType" style="width: 112px;">
                    <option value="0" @(Model.TaskType == 0 ? "selected='selected'" : "")>重复执行</option>
                    <option value="1" @(Model.TaskType == 1 ? "selected='selected'" : "")>执行1次后删除</option>
                </select>
            </td>
        </tr>
        <tr>
            <td valign="top" style="text-align: right;">
                <span class="red">*</span>任务执行周期：
            </td>
            <td valign="top" class="TaskPlan">
                执行：<select id="sel_TaskPlanType" onchange="GetTaskPlanType(this.value)" style="width: 75px;">
                    <option value="1" @(Model.TaskPlanType == 1 ? "selected" : "")>每天</option>
                    <option value="2" @(Model.TaskPlanType == 2 ? "selected" : "")>每周</option>
                    <option value="3" @(Model.TaskPlanType == 3 ? "selected" : "")>每月</option>
                </select><br />
                <div id="IntervalDay">
                    间隔：<input type="text" style="width:67px;" class="TaskIntervalDays" name="TaskIntervalDays" onkeyup="this.value=checkNum(this.value)"  value="@Model.TaskIntervalDays"/>
                    天</div>
                <div id="IntervalWeek" style="display: none;">
                    间隔：<input type="text" style="width:67px;" class="TaskIntervalWeeks" name="TaskIntervalWeeks" onkeyup="this.value=checkNum(this.value)"  value="@Model.TaskIntervalWeeks"/>
                    周，在：<br />
                    <input type="checkbox" class="WeekDay" value="1" />星期一
                    <input type="checkbox" class="WeekDay" value="2" />星期二
                    <input type="checkbox" class="WeekDay" value="3" />星期三<br />
                    <input type="checkbox" class="WeekDay" value="4" />星期四
                    <input type="checkbox" class="WeekDay" value="5" />星期五
                    <input type="checkbox" class="WeekDay" value="6" />星期六<br />
                    <input type="checkbox" class="WeekDay" value="0" />星期日
                </div>
                <div id="IntervalMonth" style="display: none;">
                    <input type="radio" class="PlanType" name="PlanType" value="1" checked='checked' />天：<input type="text" style="width: 45px;" class="DayForMonth" name="DayForMonth" onkeyup="this.value=checkNumAndValue(this.value,31)"  value="@Model.DayForMonth"/>
                    天&nbsp;-- 每：<input type="text" style="width:45px;" class="TaskIntervalMonth" name="TaskIntervalMonth" onkeyup="this.value=checkNum(this.value)"  value="@Model.TaskIntervalMonth"/>
                    月
                    <input type="hidden" name="WeekForMonth" value="0" />
                </div>
            </td>
            <td style="text-align: right;" valign="top">
                <span class="red">*</span>任务每天频率：
            </td>
            <td valign="top">
                执行频率：<br />
                <div class="editTime">
                    <label>
                        <input type="radio" class="rad_FType" name="rad_FType" checked="checked" value="0" />执行一次：</label>
                    时：<select class="sel_TimeH OnceH">
                    </select>：分<select class="sel_TimeM OnceM"></select>
                    <select class="sel_TimeS" style="display: none">
                        <option value="0"></option>
                    </select></div>
                <div class="editTime">
                    <label>
                        <input type="radio" class="rad_FType" name="rad_FType" value="1" />执行间隔：</label>
                    时：<select class="sel_TimeH IntervalH">
                    </select>：分<select class="sel_TimeM IntervalM"></select>
                    <select class="sel_TimeS" style="display: none">
                        <option value="0"></option>
                    </select>
                    <br />
                    从： 时：<select class="sel_TimeH IntervalFH">
                    </select>：分<select class="sel_TimeM IntervalFM"></select>
                    <br />
                    到： 时：<select class="sel_TimeH IntervalTH">
                    </select>：分<select class="sel_TimeM IntervalTM"></select>
                </div>
                <input id="txt_FrequencyType" type="hidden" name="FrequencyType" value="@Model.FrequencyType"/>
                <input id="txt_TaskStartTime" type="hidden" name="TaskStartTime" value="@Model.TaskStartTime"/>
                <input id="txt_TaskEndTime" type="hidden" name="TaskEndTime" value="@Model.TaskEndTime"/>
                <input id="txt_TaskEveryDayIntervalMinute" type="hidden" name="TaskEveryDayIntervalMinute" value="@Model.TaskEveryDayIntervalMinute"/>
            </td>
        </tr>
        <tr>
            <td style="text-align: right;">
                <span class="red">*</span>任务生效日期：
            </td>
            <td>
                <input type="text" class="easyui-datebox txt_TaskStartDate" onclick="SelectDate('txt_TaskStartDate');"
                    style="width: 110px;" />
                <input id="txt_TaskStartDate" type="hidden" name="TaskStartDate"  value="@Model.TaskStartDate"/>
            </td>
            <td style="text-align: right;">
                <span class="red">*</span>任务失效日期：
            </td>
            <td>
                <input type="text" class="easyui-datebox txt_TaskEndDate" onclick="SelectDate('txt_TaskEndDate');"
                    style="width: 110px;" />
                <input id="txt_TaskEndDate" type="hidden" name="TaskEndDate" value="@Model.TaskEndDate"/>
            </td>
        </tr>
        <tr>
            <td style="text-align: right;">
                重试次数：
            </td>
            <td>
                <input id="txt_RetryTimes" type="text" name="RetryTimes" maxlength="6" value="@Model.RetryTimes" style='width:100px;' onkeyup="this.value=checkNum(this.value)" />
                (次)
            </td>
            <td style="text-align: right;">
                <div class="bigType">
                    等候时间：</div>
            </td>
            <td>
                <div class="bigType">
                    时：<input id="txt_WaitTimesH" type="text" name="WaitTimes" maxlength="8" style='width: 30px;'
                        onkeyup="this.value=checkWaitTimes(this.value,1)" />
                    分：<input id="txt_WaitTimesM" type="text" name="WaitTimes" maxlength="2" style='width: 30px;'
                        onkeyup="this.value=checkWaitTimes(this.value,2)" />
                    秒：<input id="txt_WaitTimesS" type="text" name="WaitTimes" maxlength="2" style='width: 30px;'
                        onkeyup="this.value=checkWaitTimes(this.value,3)" />
                </div>
                <input id="txt_WaitTimes" type="hidden" />
            </td>
        </tr>
        <tr>
            <td style="text-align: right;" valign="top">
                描述：
            </td>
            <td colspan="3">
                <textarea id="txt_TaskDescription" name="TaskDescription" rows='3' style="width: 460px;">@Model.TaskDescription</textarea>
            </td>
        </tr>
    </table>
    <table class="searchArea" width="100%">
        <tr>
            <td valign="top" height="150">
                <input type="hidden" id="hidUserList" name="UserList" />
                @{
                    // 渲染输出列表
                    var dataUser = new ViewDataDictionary();
                    dataUser.Add("PanelTitle", "联系人信息");
                    dataUser.Add("GridID", "dataGridUser");
                    dataUser.Add("ShowAddButton", false);
                    dataUser.Add("ShowDeleteButton", false);
                    dataUser.Add("ShowOtherButton", true);
                    dataUser.Add("OtherButtonID", "btnAddUser");
                    dataUser.Add("OtherButtonValue", "添 加");
                    dataUser.Add("OtherButtonClick", "AddUser()");
                    dataUser.Add("ShowPager", false);
                    dataUser.Add("ShowLoading", false);
                    @Html.Partial("_GridPanel", dataUser);
                }
            </td>
        </tr>
        <tr class="div_dataGridModel">
            <td valign="top" height="150">
                <input type="hidden" id="hidModelList" name="ModelList" />
                <table class="listTitle">
                    <tr>
                        <td width="15">
                            <img src="/images/filesave.png" />
                        </td>
                        <td width="300">
                            加工明细列表
                        </td>
                        <td align="right">
                            <input type="button" value=" 添加 " class="button" onclick="AddModel()" />
                        </td>
                    </tr>
                </table>
                <table id="dataGridModel" class="pagTable" cellpadding="0" cellspacing="0">
                </table>
            </td>
        </tr>
        <tr>
            <td valign="top" height="150">
                <input type="hidden" id="hidGroupList" name="GroupList" />
                @{
                    // 渲染输出列表
                    var dataGroup = new ViewDataDictionary();
                    dataGroup.Add("PanelTitle", "推送明细列表");
                    dataGroup.Add("GridID", "dataGridGroup");
                    dataGroup.Add("ShowAddButton", false);
                    dataGroup.Add("ShowDeleteButton", false);
                    dataGroup.Add("ShowOtherButton", true);
                    dataGroup.Add("OtherButtonID", "btnAddGroup");
                    dataGroup.Add("OtherButtonValue", "添 加");
                    dataGroup.Add("OtherButtonClick", "AddGroup()");
                    dataGroup.Add("ShowPager", false);
                    dataGroup.Add("ShowLoading", false);
                    @Html.Partial("_GridPanel", dataGroup);
                }
            </td>
        </tr>
    </table>
    </form>
</div>
